<?php
/**
 * Description of Subcategory
 *
 * @author Admin
 */
class Asset_Model_Subcategory extends WOW_Model_Acl_Abstract
{
    public function getResourceId()
    {
        return 'Subcategory';
    }

    public function getSubcategoryById($id)
    {
        $id = (int) $id;
        return $this->getResource('Subcategory')->getSubcategoryById($id);
    }

    public function getSubcategoriesByParentId($id)
    {
        return $this->getResource('Subcategory')->getSubcategoriesByParentId($ident);
    }

    public function getSubcategoriesByParentIdent($ident)
    {
         return $this->getResource('Subcategory')->getSubcategoriesByParentIdent($ident);
    }

    public function getSubcategoryByIdent($ident)
    {
        return $this->getResource('Subcategory')->getSubcategoryByIdent($ident);
    }

    public function getParentCategory($subcatid=null,$subcat_ident=null)
    {
        return $this->getResource('Subcategory')->getParentCategory($subcatid, $subcat_ident);
    }

    public function getSubcategoryArrayByParentId($catid)
    {
        $allcat  = $this->getResource('Subcategory')->getSubcategoriesByParentId($catid);
        $ret_ar = array(' ' => 'Select Subcategory');
        foreach($allcat as $cat)
        {
            $ret_ar[$cat->subcatid] = $cat->SubCategoryName;
        }
        return $ret_ar;
    }

    public function getAllSubcategoriesArray()
    {
        $allcat  = $this->getResource('Subcategory')->getAllSubcategories();
        $ret_ar = array(' ' => 'Select Subcategory');
        foreach($allcat as $cat)
        {
            $ret_ar[$cat->subcatid] = array('subcategoryname'=>$cat->SubCategoryName,'categoryid'=>$cat->catid);
        }

        return $ret_ar;
    }

    public function getAllSubcategories()
    {
         return $this->getResource('Subcategory')->getAllSubcategories();
    }



    

    #@ TODO:: needs to be worked on ACL later
    public function setAcl(WOW_Acl_Interface $acl)
    {
        if (!$acl->has($this->getResourceId()))
        {
            $acl->add($this)->allow('Normal', $this, array('register'))
            ->allow('Moderator', $this, array('saveCategory'))
                    ->allow('Admin', $this);
        }
        $this->_acl = $acl;
        return $this;
    }

    public function getAcl()
    {
        if (null === $this->_acl) {
            $this->setAcl(new Main_Model_Acl_Main());
        }
        return $this->_acl;
    }
    
}
?>
